/**
 * 一个可以把语雀表格中的单词抓取成 json 的脚本
 * 语雀中有 21 个表格，分别是各个字母开头的单词的表格
 */

/** 总的单词列表 */
let wordlists = []
let count = 0; // 全局计数器
let wordTableList = document.getElementsByClassName("lake-table")
/** 遍历 21 个表格 */
for (let i = 0; i < wordTableList.length; i++) {
    /** 一个表格的表体位置 */

    let oneWordList = wordTableList[i].children[1];
    for (let j = 0; j < oneWordList.childElementCount; j++) {
        let oneWord = oneWordList.children[j];

        wordlists.push({
            word_id: ++count,
            word: oneWord.children[0].innerText,              // 单词
            word_prompt: oneWord.children[1].innerText,       // 单词分析
            word_translation: oneWord.children[2].innerText   // 单词翻译
        })
    }
}

let wordlist = []
for (let i = 0; i < wordlists.length; i++) {

    wordlist.push(wordlists[i])
    if ( (i + 1) % 50 === 0 ) {

        let div = document.createElement("div");
        div.innerHTML = JSON.stringify(wordlist) + '<br><hr><br>';
        document.getElementById("wordJson").appendChild(div);
        wordlist = []
    }

}
let div = document.createElement("div");
div.innerHTML = JSON.stringify(wordlist) + '<br><hr><br>';
document.getElementById("wordJson").appendChild(div);
